/*
 * task.c
 *
 *  Created on: 2021年7月17日
 *      Author: dbw
 */

#include "common.h"

#define LOG_TAG     "example_task"
#define LOG_LEVEL    LOG_LEVEL_VERBOSE
#include "logger.h"

#define TASK1_PERIOD    2000
#define TASK2_PERIOD    4000

static void task1_loop(void)
{
    static uint32_t timeout = 0;

    uint32_t cur_time = 0;

    cur_time = sys_get_time();
    if(cur_time < timeout)
    {
        return;
    }

    LOG_I("schedule task1");
    timeout = cur_time + TASK1_PERIOD;
}

static void task2_loop(void)
{
    static uint32_t timeout = 0;

    uint32_t cur_time = 0;

    cur_time = sys_get_time();
    if(cur_time < timeout)
    {
        return;
    }

    LOG_I("schedule task2");
    timeout = cur_time + TASK2_PERIOD;
}

void task_example_run(void)
{
    LOG_I("test task");

    while(1)
    {
        task1_loop();
        task2_loop();
    }
}
